package com.etone.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.etone.common.annotation.Log;
import com.etone.common.core.controller.BaseController;
import com.etone.common.core.domain.AjaxResult;
import com.etone.common.enums.BusinessType;
import com.etone.system.domain.SysRegion;
import com.etone.system.service.ISysRegionService;
import com.etone.common.utils.poi.ExcelUtil;
import com.etone.common.core.page.TableDataInfo;

/**
 * 货架区域Controller
 * 
 * @author etone
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/system/region")
public class SysRegionController extends BaseController
{
    @Autowired
    private ISysRegionService sysRegionService;

    /**
     * 查询货架区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRegion sysRegion)
    {
        startPage();
        List<SysRegion> list = sysRegionService.selectSysRegionList(sysRegion);
        return getDataTable(list);
    }

    /**
     * 导出货架区域列表
     */
    @PreAuthorize("@ss.hasPermi('system:region:export')")
    @Log(title = "货架区域", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRegion sysRegion)
    {
        List<SysRegion> list = sysRegionService.selectSysRegionList(sysRegion);
        ExcelUtil<SysRegion> util = new ExcelUtil<SysRegion>(SysRegion.class);
        util.exportExcel(response, list, "货架区域数据");
    }

    /**
     * 获取货架区域详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:region:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysRegionService.selectSysRegionById(id));
    }

    /**
     * 新增货架区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:add')")
    @Log(title = "货架区域", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRegion sysRegion)
    {
        return toAjax(sysRegionService.insertSysRegion(sysRegion));
    }

    /**
     * 修改货架区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:edit')")
    @Log(title = "货架区域", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRegion sysRegion)
    {
        return toAjax(sysRegionService.updateSysRegion(sysRegion));
    }

    /**
     * 删除货架区域
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "货架区域", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysRegionService.deleteSysRegionByIds(ids));
    }

    /**
     * 获取区域列表
     * @return
     */
    @RequestMapping("/getRegionList")
    public AjaxResult getRegionList(){
        return AjaxResult.success(sysRegionService.getRegionList());
    }

    /**
     * 根据区域id获取货架数据
     * @return
     */
    @RequestMapping("/getArrangeList")
    public AjaxResult getArrangeList(@RequestParam(value = "id") Long id){
        return AjaxResult.success(sysRegionService.getArrangeList(id));
    }

    /**
     * 根据货架id获取货架列的数据
     * @return
     */
    @RequestMapping("/getLieList")
    public AjaxResult getLieList(@RequestParam(value = "id") Long id){
        return AjaxResult.success(sysRegionService.getLieList(id));
    }
}
